﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

using Revis.VClinicNet.Core.Domain.Credentials;
using Revis.VClinicNet.App.Internal;

namespace Revis.VClinicNet.UI.Internal.Mvc.Infrastructure
{
    public interface IRoleProviderInitializer
    {
        void Initialize(IWorkerUserService iwus);
    }

    public class ClinicUserRoleProvider : RoleProvider, IRoleProviderInitializer
    {
        private IWorkerUserService _userService = null;

        public ClinicUserRoleProvider()
        {            
        }

        public void Initialize(IWorkerUserService iwus)
        {
            _userService = iwus;
        }

        public override string[] GetAllRoles()
        {
            return Enum.GetNames(typeof(WorkerUserRole));   
        }

        public override string[] GetRolesForUser(string username)
        {
            WorkerUserRole role = _userService.Find(username).Role;
            string[] roles = new string[] {
                Enum.GetName(typeof(WorkerUserRole), role)
            };
            return roles;
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            WorkerUserRole role = _userService.Find(username).Role;
            return Enum.GetName(typeof(WorkerUserRole), role)==roleName;
        }

        #region Not implemented methods

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }        

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }
       
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
